<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="就诊卡号" prop="patientNumber">
        <el-input
          v-model="queryParams.patientNumber"
          placeholder="请输入就诊卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:patient:edit']"
        >修改</el-button>
      </el-col>
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="patientList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="patientId" />
      <el-table-column label="姓名" align="center" prop="patientName" />
      <el-table-column label="手机号" align="center" prop="patientPhoneNumber" />
      <el-table-column label="就诊卡号" align="center" prop="patientCard" />
      <el-table-column label="状态"  align="center" prop="patientSt">
        <template>
          <el-button
            size="mini"
            type="success"
            >正常</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link to="/manage/archives/diagnosis/way">诊断治疗方案</router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改患者对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="patientPhoneNumber">
          <el-input v-model="form.patientPhoneNumber" placeholder="请输入患者手机号" />
        </el-form-item>
        <el-form-item label="就诊卡号" prop="patientCard">
          <el-input v-model="form.patientCard" placeholder="请输入患者就诊卡号" />
        </el-form-item>
        <el-form-item label="状态" prop="patientSt">
          <el-input v-model="form.patientSt" placeholder="请输入患者状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
 // import { listPatient, getPatient, delPatient, addPatient, updatePatient } from "@/api/system/patient";

export default {
  name: "Patient",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: 0,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生患者表格数据
      patientList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      onOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: null,
        patientNumber: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        doctorId: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        patientName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询医生患者列表 */
    getList() {
      this.loading = true;
      /*listPatient(this.queryParams).then(response => {
        this.patientList = response.rows;
        this.total = response.total;
        this.loading = false;
      });*/
      this.patientList = [
        {
          patientIds: 0,
          patientName: '小王',
          patientId: '200001',
          patientPhoneNumber: '123456789',
          patientCard: '456498795',
          patientSt: '正常'
        },
        {
          patientIds: 1,
          patientName: '小李',
          patientId: '200002',
          patientPhoneNumber: '123456789',
          patientCard: '456498795',
          patientSt: '正常'
        }
      ]
      this.total = 2
      this.loading = false
    },
    // 查看诊断治疗方案
    checkWay(){
      this.onOpen = true
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.onOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        patientIds: null
      };
      console.log(this.form)
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.patientIds)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医生患者";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();

      this.form = this.patientList[this.ids]
      console.log(this.form)
      this.open = true
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.patientId != null) {
            /*updatePatient(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });*/
            this.patientList[this.form.patientIds] = this.form;
            console.log(this.patientList)
            this.$modal.msgSuccess("修改成功");
            this.open = false
            this.getList();
          } else {
            /*addPatient(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });*/
          }
        }
      });
    },
  }
};
</script>
<style scoped>
.source{
  box-shadow: #b4bccc 1px 1px 10px 1px;
}
.sourceTwo{
  position: relative;
  top: 20px;
  box-shadow: #b4bccc 1px 1px 10px 1px;

}
.addZ{
  box-shadow: #b4bccc 1px 1px 10px 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100px;
  width: 90%;
}
.el-row{
  flex-direction: column;
  translate: 5%;
}
.el-radio-group{
  display: flex;
  flex-direction: column;
  padding: 10px;
  flex-wrap: wrap;
}
a{
  color: #00afff;
}
</style>









